import json

from django.shortcuts import render
from django.http import HttpResponse
from django.http import JsonResponse
from myfrtsite import models
from django.views.decorators.csrf import csrf_exempt
from django.forms.models import model_to_dict



# Create your views here.
@csrf_exempt
def index(request):
    return render(request, "login.html")
@csrf_exempt
def login(request):
    companyq={
        "name":"",
        "scale":"",
        "picture":"",
        "address":"",
        "description":"",
        "workingstarttime":"",
        " workingendtime":""
    }
    if request.method=="POST":
        username=request.POST.get("username")
        password=request.POST.get("password")
        if models.Company.objects.filter(companyname=username,password=password).count()>0:
            data = models.Company.objects.filter(companyname=username,password=password).values("companyname","companyscale","companypicture","companyaddress","companydescription","workingstarttime","workingendtime","workingendtime")[0]
            return JsonResponse(data)
        else:
            return HttpResponse("erro")
    else:
        return HttpResponse("erroway")
        # if request.POST.get("username")=="123" and request.POST.get("password")=="123":
        #     return render(request, "Main.html")


